﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace RestService
{
    /// <summary>
    /// ClientService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消注释以下行。 
    // [System.Web.Script.Services.ScriptService]
    public class ClientService : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod]
        public int log(string uuid,string ver) {
            return 0;
            try
            {
                using (DAL.TrainingEntities db = new DAL.TrainingEntities())
                {
                    int totalCount = db.b.Count();
                    if (totalCount > 5000)
                    {
                        return -1;
                    }

                    int rowCount = db.b.Where(pp => pp.uuid == uuid).Count();

                    if (rowCount == 0)
                    {
                        string crc = Tools.CRC.ToCRC16(uuid, true);
                        var obj = new DAL.b()
                        {
                            uuid = uuid,
                            create_date = DateTime.Now,
                            ip = Context.Request.UserHostAddress,
                            ver = ver,
                            crc = crc
                        };

                        db.b.Add(obj);
                        db.SaveChanges();
                        return 1;
                    }
                }
            }
            catch (Exception ex)
            {
                return -1;
            }
            return 0;
        }
    }
}
